from pyecharts.charts import *
from bs4 import BeautifulSoup
from code_analysis.bar_like_count import make_bar_1
from code_analysis.bar_tag import make_bar_2, make_wordcloud
from code_analysis.count_language import make_pie_4
from code_analysis.count_taglike import make_bar_4
from code_analysis.new_pie_tag import make_pie_1
from code_analysis.pie_author import make_pie_2
from code_analysis.pie_authorid import make_pie_3
from code_analysis.作者上传时间分布时间段 import make_scatter
from code_analysis.作者起名长度趋向 import make_bar_3


def page_layout():
    page = Page(layout=Page.DraggablePageLayout, page_title="全数据分析")
    page.add(

        make_pie_1(),
        make_pie_2(),
        make_pie_3(),
        make_bar_1(),
        make_bar_2(),
        make_bar_3(),
        make_wordcloud(),
        make_scatter(),
        make_pie_4(),
        make_bar_4(),
    )
    page.render("../html/最终大屏.html")
    with open("../html/最终大屏.html", "r+", encoding='utf-8') as html:
        html_bf = BeautifulSoup(html, 'lxml')
        divs = html_bf.select('.chart-container')
        divs[0]["style"] = "width:50%;height:50%;position:absolute;top:112%;left:25%;"
        divs[1]["style"] = "width:30%;height:40%;position:absolute;top:165%;left:0;"
        divs[2]["style"] = "width:30%;height:40%;position:absolute;top:255%;left:0%;"
        divs[3]["style"] = "width:50%;height:40%;position:absolute;top:210%;left:25%;"
        divs[4]["style"] = "width:50%;height:40%;position:absolute;top:60%;left:0%;"
        divs[5]["style"] = "width:60%;height:40%;position:absolute;top:165%;left:40%;"
        divs[6]["style"] = "width:50%;height:50%;position:absolute;top:10%;left:25%;"
        divs[7]["style"] = "width:50%;height:40%;position:absolute;top:60%;left:50%;"
        divs[8]["style"] = "width:30%;height:40%;position:absolute;top:255%;left:67%;"
        divs[9]["style"] = "width:30%;height:40%;position:absolute;top:255%;left:35%;"
        body = html_bf.find("body")  # 根据标签名称定位到body标签
        # body["style"] = "background-color:#333333;"  # 修改背景颜色
        body["style"] = "background-image: url(https://www.toopic.cn/public/uploads/small/1658046736867165804673655.jpg);background-attachment:fixed;background-size:100% 100%;"
        html_new = str(html_bf)  # 将BeautifulSoup对象转换为字符
        html.seek(0, 0)  # 光标移动至
        html.truncate()  # 删除光标后的所有字符内容
        html.write(html_new)  # 将由BeautifulSoup对象转换得到的字符重新写入html文件
        html.close()


if __name__ == "__main__":
    page_layout()